package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.vo.DeviceDataVo;
import com.zzyl.nursing.vo.DeviceDetailVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 设备管理Controller
 * 
 * @author Nan
 * @date 2025-06-01
 */
@RestController
@RequestMapping("/nursing/device")
@Api(tags = "设备管理的接口")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;

    /**
     *
     * @param productKey 产品key 用来查看产品详情
     * @return  返回产品信息
     */
    @GetMapping("/queryProduct/{productKey}")
    @ApiOperation(value = "查询产品详情")
    public AjaxResult queryProduct(@PathVariable String productKey){
        return deviceService.queryProduct(productKey);
    }


    // /nursing/device/{iotId} 删除设备
    /**
     *
     * @param iotId //设备id
     * @return
     */

    @ApiOperation("根据设备id 删除指定设备")
    @DeleteMapping("/{iotId}")
    public AjaxResult delDeviceByItoId(@PathVariable("iotId") String iotId){
         deviceService.delDeviceByItoId(iotId);
        return  success();
    }


    // 修改设备数据
    /**
     *
     * @param dto // 要修改设备的数据
     * @return // 返回状态码
     */
    @ApiOperation(value = "修改设备")
    @PutMapping
    public AjaxResult updateDevice(@RequestBody DeviceDto dto){

        deviceService.updateDevice(dto);
        return success();
    }





    @ApiOperation(value = "查看设备上记录的数据信息")
    @GetMapping("/queryServiceProperties/{iotId}")
    public AjaxResult queryServiceProperties(@PathVariable("iotId") String iotId){

        List<DeviceDataVo> list  = deviceService.queryServiceProperties(iotId);

        return success(list);

    }


    /**
     *
     * @param iotId //设备id
     * @return
     */

    @ApiOperation("查询设备详细数据,不包含设备上的数据信息")
    @GetMapping("/{iotId}")
    public AjaxResult deviceDetail(@PathVariable("iotId") String iotId){

       DeviceDetailVo deviceDetailVo = deviceService.deviceDetail(iotId);

        return  success(deviceDetailVo);
    }


    /**
     *
     * @param dto // 新增设备的数据
     * @return
     */
    @ApiOperation(value = "注册设备")
    @PostMapping("/register")
    public AjaxResult register(@RequestBody DeviceDto dto){

        deviceService.register(dto);
        return success();

    }


    // 查询iot平台上所有产品的接口
    /**
     * 查询iot平台上所有产品的接口
     */
    @ApiOperation("查询iot平台上所有产品")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @PostMapping("/syncProductList")
    public AjaxResult syncProductList()
    {
        deviceService.syncProductList();
        return success();
    }



    @ApiOperation("查询使用产品列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/allProduct")
    public AjaxResult allProduct()
    {
        List<ProductVo> list =   deviceService.allProduct();

        return  success(list);
    }


    /**
     * 查询设备管理列表
     */
    @ApiOperation("查询设备管理列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }


}
